package b1.players
{
	public class PlayerInfoHelper
	{
		static private var instance:PlayerInfoHelper;
		//用户本人的ID
		public var userId:int;
		//所有的玩家（用ID作为索引）
		public var players:Object;
		//所有的动物（用ID作为索引）
		public var animals:Object; 
		//所有的案件
		public var battleCases:Object;
		
		//用户本人的人人网ID
		public var rrUserId:int;
		public var rrUserName:String;
		public var rrTinyUrl:String;
		
		public function PlayerInfoHelper()
		{
			userId = -1;
			rrUserId = -1;
			players = new Object();
			animals = new Object();
			battleCases = new Object();
		}

		static public function getInstance():PlayerInfoHelper
		{
			if (!instance)
				instance = new PlayerInfoHelper();
			return instance;
		}
		
		//得到居住在某地的驻守动物（用于交战的右侧动物）
		public function getLiveAnimalsToFight(liveId:int):Array
		{
			var fightAnimals:Array = new Array();
			var liveAnimals:Array = (players[liveId] as PlayerInfo).liveAnimals;
			var liveAnimal:AnimalInfo;
			//跑路到此处的旅居动物个数
			var customAnimalCount:int = 0;
			//先找到住在此处的原籍动物
			for (var i:int = 0; i < liveAnimals.length; i++)
			{
				liveAnimal = animals[liveAnimals[i]];
				if (liveAnimal.ownerId == liveId)
				{
					fightAnimals.push(liveAnimal.id);
				}
				else
				{
					customAnimalCount++;
				}
			}
			var secondFightAnimalIndex:int = Math.random() * customAnimalCount;
			customAnimalCount = 0;
			for (i = 0; i < liveAnimals.length; i++)
			{
				liveAnimal = animals[liveAnimals[i]];
				if (liveAnimal.ownerId == liveId)
				{
					continue;	
				}
				else if (customAnimalCount == secondFightAnimalIndex)
				{
					fightAnimals.push(liveAnimal.id);
					break;	
				}
				else
				{
					customAnimalCount++;
				}
			}
			return fightAnimals;
		}
		
	}
}